
/**
 * 工具类
 */

import { message } from 'antd';
/**
 * 判空
 */
export const isEmpty = (val) => {
    if (val === undefined) return true;
    if (val === null) return true;
    if (val === '') return true;
    if (val.length === 0) return true;
    if (typeof val === 'object') {
        return Object.keys(val).length === 0;
    }
    if(typeof val === 'number') {
        return val === 0;
    }
    if (typeof val === 'string') {
        return val === '0';
    }
    if (typeof val === 'boolean') {
        return val;
    }
    if (typeof val === 'undefined'){
        return false;
    }
}

/**
 * 消息提示
 */
export const useMsg = () => {
    const [messageApi, contextHolder] = message.useMessage();
    const isMsg = ({ code, msg }) => {
        let type = 'info';
        if (code === 200) type = 'success';
        else if (code >= 400 && code < 500) type = 'warning';
        else if (code >= 500) type = 'error';
        messageApi[type](msg);
    };
    let msgTitle = contextHolder
    return { isMsg, msgTitle };
};